package com.hzdesk.media.matvector.koreabatch.client.my_paperless.custom_view;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;


import com.hzdesk.media.matvector.koreabatch.client.my_paperless.R;

/**
 * Created by Administrator on 2018/8/9.
 * 杭州席媒科技有限公司  Developers  刘传华  10
 * 佛祖镇楼 bug辟易
 */

public class MyPointAndLineView extends View {
    private String TAG = MyPointAndLineView.class.getSimpleName();
    private Paint mPaint;
    private int PaintColor;
    private int weith;
    private int heigth;
    private Context mContext;
    private int offset = 10;                                                                        // 左右偏移量
    public MyPointAndLineView(Context context) {
        this(context,null);
    }

    public MyPointAndLineView(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs,0);
    }

    public MyPointAndLineView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mContext = context;
        TypedArray array=context.obtainStyledAttributes(attrs, R.styleable.my_paint_and_line);
        PaintColor = array.getColor(R.styleable.my_paint_and_line_paint_color,0xff6CBBFF);
        array.recycle();
        init();
    }

    private void init() {
        mPaint = new Paint();
        mPaint.setAntiAlias(true);
        mPaint.setStyle(Paint.Style.FILL);
        mPaint.setColor(PaintColor);

    }


    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        weith = getWidth();
        int h = getHeight();
        if(h < weith){
            heigth = weith;
        }else{
            heigth = h;
        }
        if(weith == heigth){
            canvas.drawCircle(weith/2,weith/2,weith/2,mPaint);
        }else{
            canvas.drawRect(offset,weith/2,weith-offset,heigth,mPaint);
            canvas.drawCircle(weith/2,weith/2,weith/2,mPaint);
        }
    }
    public void reueqstMeasure(){
        //requestLayout();
        invalidate();
    }
}
